<template>
  <div class="app-container" :class="{ 'dark-mode': isDarkMode }">
    <header class="navbar">
      <div class="logo-area">
        <img 
          :src="isDarkMode ? '/src/assets/images/logo-dark-new.svg' : '/src/assets/images/logo-new.svg'" 
          alt="FHE Privacy Guard Logo" 
          class="logo-icon" 
        />
        <span class="logo-text">基于全同态加密的隐私数据保护系统</span>
      </div>
      
      <nav class="main-nav">
        <router-link to="/" class="nav-item">Home</router-link>
        <router-link to="/demo" class="nav-item">Demo</router-link>
        <router-link to="/bonus-compare" class="nav-item">Bonus</router-link>
        <router-link to="/algorithms" class="nav-item">Algorithms</router-link>
        <router-link to="/api-docs" class="nav-item">API Docs</router-link>
        <router-link to="/about" class="nav-item">About</router-link>
      </nav>
      
      <div class="user-controls">
        <button @click="toggleDarkMode" class="theme-toggle" :title="isDarkMode ? '切换到亮色模式' : '切换到暗色模式'">
          <span v-if="isDarkMode" class="material-icons">亮色模式</span>
          <span v-else class="material-icons">深色模式</span>
        </button>
        <div class="user-avatar">
          <img src="/src/assets/images/default-avatar.svg" alt="User" />
        </div>
      </div>
    </header>

    <main>
      <router-view v-slot="{ Component }">
        <transition name="fade" mode="out-in">
          <component :is="Component" />
        </transition>
      </router-view>
    </main>

    <footer class="site-footer">
      <div class="footer-content center-footer">
        <div class="certification">
          <div class="badge">FHE-Secure™ 认证</div>
        </div>
        <div class="copyright">
          <p class="contact-row">
            联系我们：
            <a href="https://gitee.com/lsm_123/fhe-privacy-guard" target="_blank" class="github-link">
              <img src="/src/assets/images/gitee.png" alt="GitHub" />
              Gitee 仓库
            </a>
          </p>
        </div>
      </div>
    </footer>
  </div>
</template>

<script setup>
import { ref } from 'vue';

// 暗黑模式状态
const isDarkMode = ref(false);

// 切换暗黑模式
function toggleDarkMode() {
  isDarkMode.value = !isDarkMode.value;
  // 保存用户偏好到本地存储
  localStorage.setItem('darkMode', isDarkMode.value ? 'true' : 'false');
}

// 初始化时检查用户偏好
if (typeof window !== 'undefined') {
  const savedMode = localStorage.getItem('darkMode');
  if (savedMode) {
    isDarkMode.value = savedMode === 'true';
  } else {
    // 检查系统偏好
    const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
    isDarkMode.value = prefersDark;
  }
}
</script>

<style>

.app-container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background-color: var(--bg-color);
  color: var(--text-color);
  transition: background-color 0.3s, color 0.3s;
}

.navbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 2rem;
  height: 70px;
  background-color: var(--navbar-bg);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  position: sticky;
  top: 0;
  z-index: 100;
}

.logo-area {
  display: flex;
  align-items: center;
}

.logo-icon {
  height: 32px;
  margin-right: 10px;
}

.logo-text {
  font-family: 'Inter', sans-serif;
  font-weight: 700;
  font-size: 1.2rem;
  color: var(--primary-color);
}

.main-nav {
  display: flex;
  gap: 1.5rem;
}

.nav-item {
  text-decoration: none;
  color: var(--text-color);
  font-weight: 500;
  padding: 0.5rem 0;
  position: relative;
  transition: color 0.2s;
}

.nav-item:hover,
.nav-item.router-link-active {
  color: var(--primary-color);
}

.nav-item.router-link-active::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 2px;
  background-color: var(--primary-color);
}

.user-controls {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.theme-toggle {
  background: none;
  border: none;
  color: var(--text-color);
  cursor: pointer;
  padding: 0.5rem;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.2s, box-shadow 0.2s;
  box-shadow: 0 4px 16px rgba(41, 98, 255, 0.15), 0 1.5px 4px rgba(0,0,0,0.08);
  font-family: 'Inter', 'Segoe UI', 'Roboto', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
  font-weight: 600;
}

.theme-toggle:hover {
  background-color: var(--hover-bg);
  box-shadow: 0 6px 24px rgba(41, 98, 255, 0.22), 0 2px 8px rgba(0,0,0,0.12);
}

.theme-toggle .material-icons {
  font-family: inherit;
  font-size: 1.1rem;
  font-family: 'Inter', sans-serif;
  font-weight: 700;
  font-size: 1.2rem;
  color: var(--primary-color);
}

.user-avatar img {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  cursor: pointer;
}

main {
  flex: 1;
  padding: 2rem;
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
}

.site-footer {
  background-color: var(--footer-bg);
  padding: 2rem;
  margin-top: 2rem;
}

.footer-content.center-footer {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  max-width: 1200px;
  margin: 0 auto;
  gap: 2rem;
}

.certification, .copyright {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.badge {
  display: inline-block;
  background-color: var(--primary-color);
  color: white;
  padding: 0.5rem 1rem;
  border-radius: 4px;
  font-weight: 500;
}

.github-link {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-color);
  text-decoration: none;
  margin-top: 0.5rem;
}

.github-link:hover {
  color: var(--primary-color);
}

.github-link img {
  width: 20px;
  height: 20px;
}

/* 页面过渡动画 */
.fade-enter-active,
.fade-leave-active {
  transition: opacity 0.3s;
}

.fade-enter-from,
.fade-leave-to {
  opacity: 0;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .navbar {
    padding: 0 1rem;
    flex-wrap: wrap;
    height: auto;
  }
  
  .main-nav {
    order: 3;
    width: 100%;
    justify-content: space-between;
    padding: 0.5rem 0;
    overflow-x: auto;
  }
  
  .logo-area {
    flex: 1;
  }
  
  main {
    padding: 1rem;
  }
}

.contact-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  margin: 0;
}
</style>